﻿using System;
namespace Colors.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="UserRole", Namespace="http://colors.x-road.eu/", Target=typeof(UserRole))]
    public class UserRoleSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected UserRole clazz;
        
        public UserRoleSerializer(UserRole clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
            Writer.WriteAttributeString("role", new global::Xtee.Core.Schema.XsdLong(((long)(clazz.Role))).ToString());
            Writer.WriteAttributeString("unit", new global::Xtee.Core.Schema.XsdLong(((long)(clazz.Unit))).ToString());
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
            var roleValue = Reader.GetAttribute("role");
            if ((roleValue != null)) {
                clazz.Role = new global::Xtee.Core.Schema.XsdLong(roleValue).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.AttributeRequiredException(">>UserRole>role");
            }
            var unitValue = Reader.GetAttribute("unit");
            if ((unitValue != null)) {
                clazz.Unit = new global::Xtee.Core.Schema.XsdLong(unitValue).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.AttributeRequiredException(">>UserRole>unit");
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        }
    }
}
